//
//  SHKViewController.m
//  YSPlayer_iOS
//
//  Created by 139994824@qq.com on 02/12/2020.
//  Copyright (c) 2020 139994824@qq.com. All rights reserved.
//

#import "SHKViewController.h"
#import <YSAVPlayerManager.h>
#import <YSPlayer_iOS/YSAVPlayerFileUtil.h>
#import <ReactiveObjC/ReactiveObjC.h>
#import "SHKTestVC.h"


@interface SHKViewController () <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) YSAVPlayerManager *playerManager;
@property (nonatomic, strong) UITableView *tableView;

@end

@implementation SHKViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initUI];
}

- (void)initUI
{
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    self.tableView = tableView;
    [self.view addSubview:tableView];
    
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
    
    
   UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 200)];
   self.tableView.tableHeaderView = headerView;
    
    
//    YSAVPlayerManager *manager = [[YSAVPlayerManager alloc] initWithCustomFrame:CGRectMake(0, 0, kScreenWidth, 200) withCurrentView:headerView];
    
 YSAVPlayerManager *manager =    [[YSAVPlayerManager alloc] initWithPlayerView:self.tableView.tableHeaderView];
    
      ///
        self.playerManager = manager;
    
        manager.assetURLs =  @[
               [NSURL URLWithString:@"http://tb-video.bdstatic.com/tieba-smallvideo/12_cc75b3fb04b8a23546d62e3f56619e85.mp4"],
               [NSURL URLWithString:@"http://tb-video.bdstatic.com/tieba-smallvideo/5_6d3243c354755b781f6cc80f60756ee5.mp4"],
               [NSURL URLWithString:@"http://tb-video.bdstatic.com/tieba-movideo/11233547_ac127ce9e993877dce0eebceaa04d6c2_593d93a619b0.mp4"]];
        manager.titles = @[@"播放标题1",@"播放标题2",@"播放标题3"];
          manager.corverNetImgUrl = @"https://upload-images.jianshu.io/upload_images/635942-14593722fe3f0695.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240";

    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.navigationController pushViewController:SHKTestVC.new animated:YES];
    if (indexPath.row == 0) {
//        NormalVC *vc = [[NormalVC alloc] init];
//        vc.onLinePlay = YES;
//        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 1){
//        NormalVC *vc = [[NormalVC alloc] init];
//        vc.onLinePlay = NO;
//        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableView.className];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:tableView.className];
    }
    if (indexPath.row == 0) {
        cell.textLabel.text = @"播放线上视频";
    }else if (indexPath.row == 1){
        cell.textLabel.text = @"播放本地视频";
    }
    return cell;
}







#if 0
- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    YSAVPlayerManager *manager = [[YSAVPlayerManager alloc] initWithCustomFrame:CGRectMake(0, 100, kScreenWidth, 400) withCurrentView:self.view];
    
    [[YSAVPlayerManager alloc] initw:view]
    
    self.playerManager = manager;
        
    NSString *path1 = [[NSBundle mainBundle] pathForResource:@"ahhah" ofType:@"mp4"];
    NSURL *url1 = [NSURL fileURLWithPath:path1];
    
    NSString *path2 = [[NSBundle mainBundle] pathForResource:@"ahhah1" ofType:@"mp4"];
       NSURL *url2 = [NSURL fileURLWithPath:path2];
    
    NSString *path3 = [[NSBundle mainBundle] pathForResource:@"ahhah2" ofType:@"mp4"];
       NSURL *url3 = [NSURL fileURLWithPath:path3];
    
    manager.assetURLs = @[url1,url2,url3];
    
   
//    manager.assetURLs =  @[
//       [NSURL URLWithString:@"http://tb-video.bdstatic.com/tieba-smallvideo/12_cc75b3fb04b8a23546d62e3f56619e85.mp4"],
//       [NSURL URLWithString:@"http://tb-video.bdstatic.com/tieba-smallvideo/5_6d3243c354755b781f6cc80f60756ee5.mp4"],
//       [NSURL URLWithString:@"http://tb-video.bdstatic.com/tieba-movideo/11233547_ac127ce9e993877dce0eebceaa04d6c2_593d93a619b0.mp4"]];
    manager.titles = @[@"播放标题1",@"播放标题2",@"播放标题3"];
    manager.corverNetImgUrl = @"https://upload-images.jianshu.io/upload_images/635942-14593722fe3f0695.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240";
    
    @weakify(self);
    manager.playDidFinish = ^{
        @strongify(self);
        [self.playerManager playTheNext];
    };
    
        
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = UIColor.purpleColor;
    [self.view addSubview:btn];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-20);
        make.centerX.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(100, 40));
    }];
    
    [[btn rac_signalForControlEvents:UIControlEventTouchUpInside]
     subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        [self.navigationController pushViewController:SHKTestVC.new animated:YES];
    }];
}


- (BOOL)prefersStatusBarHidden {
    return self.playerManager.isStatusBarHidden;
}


- (void)dealloc
{
    NSLog(@"%s",__func__);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#endif

@end
